package com.bfxy.rabbit.producer.service;

import com.bfxy.rabbit.producer.constant.BrokerMessageConstant;
import com.bfxy.rabbit.producer.constant.BrokerMessageStatus;
import com.bfxy.rabbit.producer.entity.BrokerMessage;
import com.bfxy.rabbit.producer.mapper.BrokerMessageMapper;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by Guaguaerhao on 2021/6/4 22:45
 */
@Service
public class MessageStoreService {

    @Autowired
    private BrokerMessageMapper brokerMessageMapper;

    public void insert(BrokerMessage brokerMessage) {
        this.brokerMessageMapper.insert(brokerMessage);
    }

    public void success(String brokerMessageId) {
        this.brokerMessageMapper.changeBrokerMessageStatus(
                brokerMessageId,
                BrokerMessageStatus.SEND_OK.getCode(),
                new Date()
        );
    }

    public void fail(String brokerMessageId) {
        this.brokerMessageMapper.changeBrokerMessageStatus(
                brokerMessageId,
                BrokerMessageStatus.SEND_FAIL.getCode(),
                new Date()
        );
    }

}
